package com.wkh.project.trigger.listener;

import com.alibaba.fastjson2.JSON;
import com.wkh.project.domain.service.LogAnalyticalServiceImpl;
import com.wkh.project.sdk.model.LogMessage;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.listener.MessageListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author wangkehua
 * 监听类
 */
@Component
@Slf4j
public class MonitorLogListener implements MessageListener<LogMessage> {

    @Resource
    private LogAnalyticalServiceImpl logAnalyticalService;
    @Override
    public void onMessage(CharSequence charSequence, LogMessage logMessage) {
        try {
            log.info("监听监控日志消息，解析存储: {}", JSON.toJSONString(logMessage));
            logAnalyticalService.doAnalytical(logMessage.getSystemName(),logMessage.getClassName(),logMessage.getMethodName(),logMessage.getLogList());
        } catch (Exception e) {
            log.error("监听监控日志消息，解析失败: {}", JSON.toJSONString(logMessage), e);
        }
    }
}
